Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
"require" not supported even though I'm using "import"

Code:

import fetch from 'node-fetch';

Error:

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\youar_mnnijcy\Documents\Work\Typescript\CoredV5-TS\node_modules\node-fetch\src\index.js from C:\Users\youar_mnnijcy\Documents\Work\Typescript\CoredV5-TS\src\commands\general\ping.ts not supported.
Instead change the require of index.js in C:\Users\youar_mnnijcy\Documents\Work\Typescript\CoredV5-TS\src\commands\general\ping.ts to a dynamic import() which is available in all CommonJS modules.    
    at Object.<anonymous> (C:\Users\youar_mnnijcy\Documents\Work\Typescript\CoredV5-TS\src\commands\general\ping.ts:15:38)
    at Module.m._compile (C:\Users\youar_mnnijcy\AppData\Local\Yarn\Data\global\node_modules\ts-node\dist\index.js:704:29)
    at Object.require.extensions.<computed> [as .ts] (C:\Users\youar_mnnijcy\AppData\Local\Yarn\Data\global\node_modules\ts-node\dist\index.js:706:16)
    at bot.<anonymous> (C:\Users\youar_mnnijcy\Documents\Work\Typescript\CoredV5-TS\src\classes\bot.ts:43:44)
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\youar_mnnijcy\Documents\Work\Typescript\CoredV5-TS\src\classes\bot.ts:5:58) {
  code: 'ERR_REQUIRE_ESM'
}

Additional Information:

"node-fetch": "^3.0.0"

"@types/node-fetch": "^3.0.3"

When I tried downgrading to v2.6.2, I got an error from my IDE to install @types/node-fetch, which I installed, but I still get that error.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

How I fixed this problem:

Uninstall node-fetch and the types,

npm uninstall node-fetch npm uninstall @types/node-fetch

Install any 2. version of node-fetch, I used node-fetch@^2.6.1 with @types/node-fetch@2.5.12

Installation:

npm install node-fetch@^2.6.1 npm install --save-dev @types/node-fetch@2.5.12

about 4 years ago · Juan Pablo Isaza Denunciar

0

By default, TypeScript will compile your code into ES3 JavaScript. This will cause your import to be compiled into this. You can change that behavior by switching the target in your tsconfig to ES6 or ES2015.

This way the generated JavaScript will use import instead of require and work with node-fetch@3.x

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda